<template>
	<div>
		<el-row style="margin: 10px 0;">
			<el-col :span="2">姓名:</el-col>
			<el-col :span="20">
				<el-input v-model="item.name"></el-input>
			</el-col>
		</el-row>
		<el-row style="margin: 10px 0;">
			<el-col :span="2">电话:</el-col>
			<el-col :span="20">
				<el-input v-model="item.tel"></el-input>
			</el-col>
		</el-row>
		<el-row style="margin: 10px 0;">
			<el-col :span="2">年龄:</el-col>
			<el-col :span="20">
				<el-input v-model="item.age"></el-input>
			</el-col>
		</el-row>
		<el-row style="margin: 10px 0;">
			<el-col :span="2">性别:</el-col>
			<el-col :span="20">
				<el-select v-model="item.sex">
					<el-option label="男" value="男"></el-option>
					<el-option label="女" value="女"></el-option>
				</el-select>
			</el-col>
		</el-row>
		<el-button @click="handleSubmit">提交</el-button>
	</div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'
const router = useRouter()
const item = ref({
	id: '',
	age: '',
	name: '',
	sex: '女',
	tel: ''
})

const handleSubmit = () => {
	axios.post('/api/list/add', { item: item.value }).then((resp) => {
		const { code } = resp.data
		if(code === 200) router.push('/list')
	})
}

</script>